package com.wswy.wzcx.model.coupon

import android.os.Parcel
import android.os.Parcelable
import android.text.format.DateFormat
import com.google.gson.annotations.SerializedName
import com.wswy.wzcx.utils.StringUtils

class CouponModel (

        @SerializedName("id") val id :Long = 0L,

        @SerializedName("name") val title:String?=null,

        @SerializedName("amount") val amount : String?=null,

        @SerializedName("validityEnd") val validityEnd : Long = 0L

) : Parcelable{

    val expiredStr by lazy {
        DateFormat.format("yyyy-MM-dd",validityEnd*1000)
    }

    val amountStr by lazy {
        StringUtils.parseToMoney(amount).stripTrailingZeros().toPlainString()
    }

    constructor(parcel: Parcel) : this(
            parcel.readLong(),
            parcel.readString(),
            parcel.readString(),
            parcel.readLong()) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeLong(id)
        parcel.writeString(title)
        parcel.writeString(amount)
        parcel.writeLong(validityEnd)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun toString(): String {
        return "CouponModel(id=$id, title=$title, amount=$amount, validityEnd=$validityEnd)"
    }

    companion object CREATOR : Parcelable.Creator<CouponModel> {
        override fun createFromParcel(parcel: Parcel): CouponModel {
            return CouponModel(parcel)
        }

        override fun newArray(size: Int): Array<CouponModel?> {
            return arrayOfNulls(size)
        }
    }



}